package ReviewStack;

import java.util.Stack;

public class Pb {
    public boolean pb(String s){
        Stack<Character> s1=new Stack<>();
        for(int i=0;i<s.length();i++){
            char c=s.charAt(i);
            if(c=='('||c=='{'||c=='['){
                s1.push(c);
            }else {
                if(s1.isEmpty()){//右括号多
                    System.out.println("左括号栈为空！");
                    return false;
                }
                char c2=s1.peek();
                if(c2=='('&&c==')'||c2=='['&&c==']'||c2=='{'&&c=='}'){//括号顺序不匹配
                    s1.pop();
                }else{
                    return false;
                }
            }
        }
        if(!s1.isEmpty()){//左括号多
            return false;
        }
        return true;
    }
}
